#!/usr/bin/perl -w  # for syntax highlighting
package clreqd_modules;
use clnet qw(CLNET2_gen_ip_list CLNET2_validate_ips);

sub clreqd_add_node {
my %ARGS=@_;

	my $ips=$ARGS{IPS} if exists($ARGS{IPS});
	my $node=$ARGS{NODE};

	#########################################################
	# Double check that at least one IP address has been	#
	# specified.						#
	#########################################################
	if(defined($ips) && !length($ips)) {
		return "ERROR No IP addresses specified for host.";
	}
	if(defined($ips)) {
		my $valid=CLNET2_validate_ips($ips);
		if(!$valid) {
			return "ERROR IP address specified has invalid format.";
		}
		my ($nips,$masks)=CLNET2_gen_ip_list($ips);
		if(!defined($nips)) {
			return "ERROR IP address list is invalid.";
		}
		$ips=$nips;
	}

	my ($rc,$err)=$::REQD->add_host_entry($node,$ips);
	if($rc==1) {
		($rc,$err)=$::REQD->write_config("$::ENV{TRUECL_CFG}/clreqd.xml");
		if($rc==0) {
			return "ERROR $err";
		}
		return "OK";
	}
	return "ERROR $err";
}

1;
